from exts import db


class ProductModel(db.Model):
    """商品类"""
    __tablename__ = "product"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    product_id = db.Column(db.BigInteger, nullable=False)
    product_name = db.Column(db.String(length=255), nullable=False)
    product_category_id = db.Column(db.String(length=255), nullable=False)
    amazon_id = db.Column(db.String(length=255), nullable=False)
    product_image = db.Column(db.String(length=255), nullable=False)
    product_category = db.Column(db.String(length=255), nullable=False)
    product_ugc_tag = db.Column(db.String(length=255), nullable=False)


class RatingsModel(db.Model):
    """评分类"""
    __tablename__ = "ratings"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    user_id = db.Column(db.BigInteger, nullable=False)
    product_id = db.Column(db.BigInteger, nullable=False)
    rating = db.Column(db.Float, nullable=False)
    rating_time = db.Column(db.DateTime, nullable=False)


class UserModel(db.Model):
    """用户类"""
    __tablename__ = "user"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    user_id = db.Column(db.BigInteger, nullable=False)
    account = db.Column(db.String(length=255), nullable=False)
    password = db.Column(db.String(length=255), nullable=False)
    email = db.Column(db.String(length=255), nullable=False)


class HistoricalTopProductsModel(db.Model):
    """历史热门类"""
    __tablename__ = "historical_top_products"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    product_id = db.Column(db.BigInteger, nullable=False)


class RecentlyTopProductsModel(db.Model):
    """近期热门类"""
    __tablename__ = "recently_top_products"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    product_id = db.Column(db.BigInteger, nullable=False)
    product_count = db.Column(db.BigInteger, nullable=False)
    year_month = db.Column(db.String(length=255), nullable=False)


class AverageProductsModel(db.Model):
    """商品平均评分类"""
    __tablename__ = "average_products"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    product_id = db.Column(db.BigInteger, nullable=False)
    product_rating = db.Column(db.Float, nullable=False)


class ContentBasedProductRecs(db.Model):
    """基于商品内容相似度推荐"""
    __tablename__ = "content_based_product_recs"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    product_id = db.Column(db.BigInteger, nullable=False)
    recommendations = db.Column(db.JSON, nullable=False)


class UserRecsModel:
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    user_id = db.Column(db.BigInteger, nullable=False)
    recommendations = db.Column(db.JSON, nullable=True)


class AlsUserRecsModel(UserRecsModel, db.Model):
    """基于隐语义模型的用户推荐列表"""
    __tablename__ = "als_user_recs"


class StreamUserRecsModel(UserRecsModel, db.Model):
    """基于自定义实时模型的用户推荐列表"""
    __tablename__ = "stream_user_recs"


class ProductRecsModel:
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    product_id = db.Column(db.BigInteger, nullable=False)
    recommendations = db.Column(db.JSON, nullable=True)


class AlsProductRecsModel(ProductRecsModel, db.Model):
    """基于隐语义模型的协同过滤推荐-商品相似度"""
    __tablename__ = "als_product_recs"


class ItemCFProductRecsModel(ProductRecsModel, db.Model):
    """基于物品的协同过滤相似推荐-商品相似度"""
    __tablename__ = "itemCF_product_recs"
